package com.als.healthymananger.controller;

import com.als.healthymananger.entity.User;
import com.als.healthymananger.utils.RespBean;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Tag(name = "登录", description = "登录相应的操作，如：注册、注销等")
public interface LoginApi {

    /**
     * 登录
     * @return
     */
    @PostMapping("/sign-in")
    @Operation(summary = "登录", description = "如果http头中有Authorization则可以不输入用户名、密码，且默认7天内免密登录")
    @Parameters({
            @Parameter(name = "username", description = "用户名", in = ParameterIn.QUERY, required = false),
            @Parameter(name = "password", description = "密码，由6~26位数字或字母组成，不允许有其它字符", in = ParameterIn.QUERY, required = false),
            @Parameter(name = "remember", description = "七天内自动登录,值为true、false", in = ParameterIn.QUERY, required = false),
            @Parameter(name = "authorization", description = "在http头带有token信息，实现自动登录", in = ParameterIn.HEADER, hidden = true, required = false)
    })
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "登录成功"),
            @ApiResponse(responseCode = "400", description = "登录失败")
    })
    public RespBean signIn(@RequestParam(value = "username", required = false)String username,
                           @RequestParam(value = "password", required = false)String password,
                           @RequestParam(value = "remember", required = false)boolean remember,
                           @RequestHeader(value = "authorization", required = false)String authorization);

    /**
     * 注册
     * @return
     */
    @PostMapping("/sign-up")
    @Operation(summary = "注册", description = "需要输入姓名和密码，姓名是将来找回密码的关键")
    @Parameters({
            @Parameter(name = "username", description = "用户名,11位内字符", in = ParameterIn.QUERY, required = true),
            @Parameter(name = "password", description = "密码，26位内数字、字母组成", in = ParameterIn.QUERY, required = true),
            @Parameter(name = "userType", description = "用户类型，mananger、master、member之一", in = ParameterIn.QUERY, schema = @Schema(allowableValues = {"mananger, master, member"}), required = true)
    })
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "注册成功"),
            @ApiResponse(responseCode = "400", description = "注册失败")
    })
    public RespBean signUp(@RequestParam(value = "username", required = true)String username,
                           @RequestParam(value = "password", required = true)String password,
                           @RequestParam(value = "userType", required = true)String userType);

    /**
     * 退出登录
     * 将token从数据库中删除
     * 需要http中带token信息
     * @return
     */
    @DeleteMapping("/sign-out")
    @Operation(summary = "注销", description = "删除掉数据库中保存的保存的token", security = @SecurityRequirement(name = "bearer-key"))
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "注销成功"),
            @ApiResponse(responseCode = "400", description = "注销失败")
    })
    @Parameter(name = "Authorization", in = ParameterIn.HEADER, required = true, hidden = true)
    public RespBean signOut(@RequestHeader("Authorization")String authorization);

    /**
     * 找回密码
     * @return
     */
    @PutMapping("/forget")
    @Operation(summary = "更换密码", description = "通过用户名、姓名更换密码")
    @Parameters({
            @Parameter(name = "username", description = "用户名", in = ParameterIn.QUERY, schema = @Schema(allowableValues = {"mananger", "master", "member"}), required = true),
            @Parameter(name = "name", description = "注册时输入的姓名", in = ParameterIn.QUERY, required = true),
            @Parameter(name = "password", description = "密码，由6~26位数字或字母组成，不允许有其它字符", in = ParameterIn.QUERY, required = true)
    })
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "更换密码成功"),
            @ApiResponse(responseCode = "400", description = "更换密码失败")
    })
    public RespBean forget(@PathVariable("username")String username,
                           @RequestBody @RequestParam("name")String name,
                           @RequestBody @RequestParam("password")String password);
}
